<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>阻止事件默认行为</title>
  <script>
    window.onload = function() {
      // 1.获取需要阻止默认行为的dom节点
      var a = document.getElementsByTagName('a')[0]
      var form = document.getElementsByTagName('form')[0]
      // 绑定点击事件
      a.onclick = function(event) {
        // 阻止事件默认行为
        event.preventDefault()
      }
      form.onclick = function(event) {
        // 阻止事件默认行为
        event.preventDefault()
      }
    }
  </script>
</head>
<body>
  <a href="http://www.baidu.com">百度一下</a>
  <form action="./1-事件绑定.html">
    <button type="submit">提交</button>
  </form>
</body>
</html>